<?php
namespace app\fruit\controller;
use app\common\Base;
use think\Db;

class TeacherFruitQuery extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$where = [];
		$termId = input("termId");
		$type = input("类别");
		$teacherName = input("teacherName");
		$page = input("page");
		$rows = input("rows");
		if($termId) $where["学期ID"] = $termId;
		if($type) $where["类别"] = $type;
		if($teacherName) $where["姓名"] = array("like",$teacherName);
		$result = Db::table('教师成果')->alias('a')
				  ->join('学期名称 b','a.学期ID = b.ID','LEFT')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->field("a.ID,a.学期ID,a.教师ID,a.类别,a.项目名称,a.项目内容,a.教师ID,a.获奖级别,a.获奖等第,a.获奖时间,a.立项时间,a.结题时间,a.颁发单位,a.加分,a.备注,b.学期名称,c.姓名")
				  ->where($where)
				  ->order("学期ID desc,ID desc")
				  ->page($page, $rows)
		          ->select();
		$count = Db::table('教师成果')->alias('a')
				  ->join('学期名称 b','a.学期ID = b.ID','LEFT')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->where($where)
				  ->count();
		$grid['rows'] = selectResult($result);
        $grid['total'] = $count;
		return $grid;
	}

	public function getTeacherFruitConf(){
		$where["参数名称"] = request()->param("type");
		$result = Db::table("教师成果参数")
				  ->field("参数值 value")
				  ->where($where)
				  ->find();
		$array = explode(",", $result["value"]);
		$list = [];
		foreach ($array as $key => $value) {
			$list[$key] = array("text"=>$value, "value"=>$value);
		}
		return $list;
	}

}
